#include<stdio.h>
#include<unistd.h>


//这是一段测试孤儿进程状态的代码
int main()
{
	pid_t id = fork();
	if(id<0)
	{
		perror("fork");
		return 1;
	}
	else if(id>0)
	{
		printf("Parent[%d] is about to quit\n",getpid());
		sleep(5);
		exit(2);
	}
	else
	{
		printf("Child[%d]'s parent's pid is %d \n",getpid(),getppid());
		sleep(10);	
		while(1)
		{
			printf("Child[%d]'s new parent's pid is %d\n",getpid(),getppid());
			sleep(1);
		}
	}

	return 0;
}
